<template>
	<!-- 我的药房 -->
	<view class="Pharmacy">
		<view class="header">
			<image mode="widthFix" :src="vuex_httpImageUrl && vuex_httpImageUrl+'static/my/yfNav0.png'" alt=""  @click="C_btn('./PharmacyRecords/PharmacyRecords')">
			<image mode="widthFix" :src="vuex_httpImageUrl && vuex_httpImageUrl+'static/my/yfNav1.png'" alt="" @click="C_btn('./childDate/childDate')">
		</view>
		<view class="list">
			<view v-for="(item,index) in list" :key="index"> 
				<text>{{item.name}}</text> 
				<view>
					<text>{{item.cont}}</text>
					<text class="del" @click="delThis(index)">删除</text>
				</view>
			</view>
		</view>
		<view class="add" @click="model.visible = true">添加</view>
		<view class="submit" @click="submit">确定</view>
		
		<h-addmodel 
			:visible='model.visible' 
			@closeModel='model.visible = false'
			@modelDb='modelDb'
		></h-addmodel>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				
				model:{
					visible:false
				}
			};
		},
		methods:{
			C_btn(url){uni.navigateTo({url})},
			modelDb(val){
				console.log(val,'-=');
				this.list.unshift(val)
				this.model.visible = false;
			},
			delThis(idx){
				uni.showModal({
					title:'提示',
					content:'您确定要删除这条数据吗?',
					success:res=>{
						if(res.confirm){
							this.list.splice(idx,1)
						}
					}
				})
			},
			submit(){
				console.log(JSON.stringify(this.list),'JSON.stringify(this.list)');
				
				if(this.list.length == 0){this.$u.toast('请最少添加一个药方');return};
				this.$u.post('/appuser/add_prescrip',{
					json:JSON.stringify(this.list)
				}).then(res=>{
					console.log(res);
					if(res.code == 0){
						this.$u.toast(res.msg)
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.del{
		color: red;
		margin-left: 10rpx;
	}
	.header {
		background-color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		padding: 15rpx;

		>view {
			text-align: center;
			padding: 30rpx 0;
			border-radius: 20rpx;
			border: 1px solid red;
			width: 48%;
		}
	}

	.list {
		overflow: hidden;
		width: 95%;
		margin: 20rpx auto;
		border-radius: 20rpx;
		background-color: #FFFFFF;
		padding: 0 30rpx;
		box-sizing: border-box;

		>view {
			display: flex;
			justify-content: space-between;
			padding: 40rpx 0;
			border-bottom: 1px solid rgba(0, 0, 0, .05);

			.sex {
				display: flex;
				align-items: center;

				>view {
					margin-left: 30rpx;
					display: flex;
					align-items: center;

					.seximg {
						width: 25rpx;
						height: 25rpx;
						margin-right: 10rpx;
					}
				}
			}
		}
	}
	
	.add{
		margin-left: 20rpx;
		background: #288EE7;
		padding: 10rpx 30rpx;
		display: inline-block;
		border-radius: 10rpx;
		color: #FFFFFF;
		
	}
	.submit {
		text-align: center;
		padding: 20rpx;
	}

	.model{
		background-color: #FFFFFF;
		width: 60%;
		margin: auto;
		padding: 50rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
		image{
			max-width: 100%;
			display: block;
			margin: auto;
		}
	}
</style>
